<template>
  <a-card :bordered="false">
    <a-spin :spinning="spinning != 0">
      <!-- 查询区域-->

      <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin-top: 10px">
            <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
            <a-button @click="handleBatchDel" type="default"
                      icon="delete" v-test>{{ $t('m.common.button.delete') }}</a-button>

         <!--
         <a-button type="default" icon="download" @click="handleExportXls('YchDemoFilepreview')">{{ $t('m.common.button.export') }}</a-button>
          <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                    @change="handleImportExcel">
            <a-button type="default"  icon="import">{{ $t('m.common.button.import') }}</a-button>
          </a-upload>-->
    </div>

      <!-- table区域-begin -->
    <div>
        <a-table
                ref="table"
                size="middle"
                bordered
                :rowKey="rowKey"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="pagination"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                @change="handleTableChange"
                :customRow="clickThenCheck"
        >
            <template slot="serialNum" slot-scope="text,record,index">
              {{(pagination.current-1) * pagination.pageSize + parseInt(index) + 1}}
            </template>
            <template slot="action" slot-scope="text, record">
              <a @click="preview(record)">{{$t('m.common.button.preview')}}</a>
              <a-divider type="vertical" />
              <a @click="handleEdit(record)">
                {{ $t('m.common.button.update') }}
              </a>
              <a-divider type="vertical" />
              <a @click="handleDel(record)" v-test>{{ $t('m.common.button.delete') }}</a>
            </template>

        </a-table>
    </div>
    </a-spin>

    <!-- 表单区域 -->
    <FilePreviewFormDialog ref="form" @refreshParent="modalFormOk"/>
  </a-card>
</template>
<script>

  import {ViewMixin} from '@/mixins/ViewMixin'
  import FilePreviewFormDialog from './modules/FilePreviewFormDialog'
  import YchConstant from '@/api/YchConstant'

  export default {
    name: "FilePreviewViewList",
    mixins: [ViewMixin],
    components: {
      FilePreviewFormDialog,
    },
    data() {
      return {
        formCode: 'FilepReviewForm',
        tableName: 'ych_demo_filepreview',
        dictConfig: {},
        optionConfig: {},
        columns: [
            {
                title:this.$t('m.common.label.number'),
                dataIndex: '',
                key: 'rowIndex',
                width: 50,
                align: "center",
                scopedSlots: { customRender: 'serialNum' },
            },
            {
                title: this.$t('m.common.label.fileName'),
                dataIndex: 'fileName',
                align: 'center',
            },
            /**
            {
                title: '文件详情',
                dataIndex: 'fileDesc',
                align: 'center',
            },*/
            {
                title: this.$t('m.common.label.operate'),
                dataIndex: 'action',
                align: "left",
                width:"35%",
                scopedSlots: { customRender: 'action' },
            }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/demo/filepreview/list",
          delete: YchConstant.PREFIX_SYSTEM + "/demo/filepreview/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/demo/filepreview/deleteBatch",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/demo/filepreview/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/demo/filepreview/importExcel",
        },
      }
    },
    computed: {
      importExcelUrl: function () {
        return `${bootConfig[process.env.NODE_ENV].VUE_APP_URL}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      preview(record){
        let filePreviewUrl = bootConfig[process.env.NODE_ENV].VUE_APP_FILEPREVIEW_URL
        let url = record.url;
        url = encodeURIComponent(this.$Base64.encode(url))
        window.open(filePreviewUrl+"/onlinePreview?url="+url)
      },

    },
    watch: {
      pkFlg() {
        this.watchPk()
      }
    }
  }
</script>
<style scoped>
</style>
